import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem } from '../utils/storage.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 存储当前用户的token数据
    // user: JSON.parse(window.localStorage.getItem('TOKEN_KEY')) || {}
    user: getItem('TOKEN_KEY') || {}
  },
  getters: {
  },
  mutations: {
    // 存储token的方法
    setUser (state, data) {
      state.user = data
      // window.localStorage.setItem('TOKEN_KEY', JSON.stringify(state.user))
      setItem('TOKEN_KEY', state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
